package com.neuedu.controller;

import com.alibaba.fastjson2.JSONObject;
import com.neuedu.base.R;
import com.neuedu.model.FangChan;

import com.neuedu.model.XiaoQu;
import com.neuedu.service.HouseService;

import com.neuedu.service.impl.HouseServiceImpl;

import com.neuedu.vo.PageVO;

import java.util.Map;

public class HouseController {
    private HouseService houseService = new HouseServiceImpl();

    public R PAGE(JSONObject jsonObject) {

        //String minDate,String maxDate,String likeName
        String minDate = jsonObject.getString("minDate");
        String maxDate = jsonObject.getString("maxDate");
        String likeName = jsonObject.getString("likeName");
        Integer pageNo = jsonObject.getInteger("pageNo");
        Integer pageSize = jsonObject.getInteger("pageSize");
        PageVO<FangChan> pageVO = houseService.selectxianshi(minDate, maxDate, likeName, pageNo, pageSize);


        return R.ok("分页数据查询成功").setData(pageVO);
    }

    public R ADD(JSONObject jsonObject) {

        String suoshuxiaoqu = jsonObject.getString("suoshuxiaoqu");
        String dongshu = jsonObject.getString("dongshu");
        String fangchanmingcheng = jsonObject.getString("fangchanmingcheng");
        String huzhumingcheng = jsonObject.getString("huzhumingcheng");
        String lianxifangshi = jsonObject.getString("lianxifangshi");
        Integer fangjianshu = jsonObject.getInteger("fangjianshu");
        String danyuan = jsonObject.getString("danyuan");
        String louceng = jsonObject.getString("louceng");
        String miaoshu = jsonObject.getString("miaoshu");
        String ruzhushijian = jsonObject.getString("ruzhushijian");

        FangChan fangChan=new FangChan();
        fangChan.setSuoshuxiaoqu(suoshuxiaoqu);
        fangChan.setDongshu(dongshu);
        fangChan.setFanchanmingcheng(fangchanmingcheng);
        fangChan.setHuzhumingcheng(huzhumingcheng);
        fangChan.setLianxifangshi(lianxifangshi);
        fangChan.setFangjianshu(fangjianshu);
        fangChan.setDanyuan(danyuan);
        fangChan.setLouceng(louceng);
        fangChan.setMiaoshu(miaoshu);
        fangChan.setRuzhushijian(ruzhushijian);
        int result=houseService.addHouse(fangChan);
        if (result > 0) {
            return R.ok("新增成功");
        } else {
            return R.error("新增失败");
        }
    }
    public R del(Map<String,String[]> map){
        String[] ScId= map.get("fangchanid");
        Integer[] ids=new Integer[ScId.length];
        for (int i=0;i<ScId.length;i++){
            ids[i]=Integer.parseInt(ScId[i]);
        }
        int result =houseService.shanchuHouse(ids);
        if (result > 0) {
            return R.ok("删除成功");
        } else {
            return R.error("删除失败");
        }

    }
}


